//inspired by www.dzone.com
$(function () {
	//var m = window.location.search.match(/p=(\d+)/);
	var curPage = 0;
	var loading = false;
	var pageContent;
	var url;
	$(".page-footer-no").click(function () {
		if(!loading){
			loading = true;
			curPage = $(this).attr("pgno")?$(this).attr("pgno"):0;
			pageContent = $("#content-page-"+curPage)[0];
			if (curPage >= 0 && !pageContent) { //&& 
				url = window.location + (window.location.search !== "" ? "&" : "?") + "method=ajax&pgno=" + curPage;			
				$("#progressIndicator")[0].style.display = "block";
				$.ajax({type:"GET", dataType:"html", url:url, 
					success:function (html) {
						html = $.trim(html);
						if (html) $("#content-inner").append(html);
					}, 
					complete:function () {
						loading = false;
						//urchinTracker(window.location.pathname + (window.location.search != "" ? "" + window.location.search + "&" : "?") + "p=" + (curPage));
						//_qacct = "p-ebK_XdQH1HeLo";
						//quantserve();
						$("#progressIndicator")[0].style.display = "none";
						$("#content-page-footer-link").focus();
					}
				});
			}else{
				loading = false;
				$("#content-page-footer-link").focus();
			}
		}
		return false;
	});
	
	//----auto login----------
	if($('#not_check_autologin').length){//check the element is exist
		$.ajax({type:"GET", dataType:"html", url:"ajaxautologin.jsp", 
			success:function (html) {
				html = $.trim(html);
				if (html) $("#not_check_autologin").append(html);
			}, 
			complete:function () {
				$("#not_check_autologin").style.display = "none";
			}
		});
	}
	
	//----date picker----------
	$.datepicker.setDefaults({showOn: 'both', buttonImageOnly: true, buttonImage: 'IMAGES/calendar.gif', buttonText: 'Calendar'});
	
  $('#startDate').datepicker({dateFormat: 'yy-mm-dd'});  
  $('#endDate').datepicker({dateFormat: 'yy-mm-dd'});  
  $('#startDate').change(function(){
  	$('#startDateHidden').val($(this).val());
  });
  $('#endDate').change(function(){
  	$('#endDateHidden').val($(this).val());
  });
    	
});